/**
 * Created by c66 on 2017/7/18.
 */
/**
 * 时间格式取年月日
 * @param time
 * @returns {*}
 */
function getYearMonthDate(time) {
    if(time!=null) {
        var YMD = time.split(" ")[0];  // 年月日
        var HMS = time.split(" ")[1];  // 时分秒
        return YMD;
    }
    return null;
}
layui.config({
    base: '../../static/js/layuiModulesEX/'
});
layui.use(['paging','form','laytpl'], function() {
    var $ = layui.jquery,
        paging = layui.paging(),
        layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
        layer = layui.layer, //获取当前窗口的layer对象
        form = layui.form(),
        laytpl = layui.laytpl;


    paging.init({
        openWait: true,
        url:'/notice/findByCondition',
        elem: '#content', //内容容器
        params: { //发送到服务端的参数
            // publisherid:publisherid
            ispublic:"1",
            schoolid:studentInfo.schoolid
        },
        contentType : "application/json; charset=utf-8",
        type: 'POST',
        tempElem: '#tpl', //模块容器
        pageConfig: { //分页参数配置
            elem: 'paged', //分页容器
            pageSize:10 //分页大小
        },
        success: function() {//渲染成功的回调
            //alert('渲染成功');
        },
        fail: function(msg) { //获取数据失败的回调
            //alert('获取数据失败')
        },
        complate: function() { //完成的回调
            //alert('处理完成');
            $('#content').children('tr').each(function() {
                //获取每行记录的id值
                var $that = $(this).children('td:last-child');
                var id = $that.children('a[data-opt=details]').data('id');
                console.log(id);
                $that.children('a[data-opt=details]').on('click', function() {
                    vm.show = false;
                   console.log(vm.show);
                    axios.get('/notice/findById/'+id)
                        .then(function (response) {
                            console.log(response.data.data);
                            vm.notice = response.data.data.notice;
                            vm.composerName=response.data.data.composerName;
                            console.log(vm.notice);
                            console.log(vm.composerName);
                            var divshow = $("#hello");
                            divshow.text("");// 清空数据
                            console.log(vm.notice.content);
                            divshow.html(vm.notice.content); // 添加Html内容，不能用Text 或 Val
                        })

                        .catch(function (response) {
                            console.log(response);
                        });
                });
            });
        }
     });

    //搜索
    $('#search').on('click', function() {
        paging.get({
            keyword:$('#searchVal').val(),
            publisherid:publisherid
        });
        parent.layer.alert('你点击了搜索按钮')
    });

    var vm = new Vue({
        el:'#Vue',
        data:{
            show:true,
            notice:{
                publisherid:publisherid
            },
            composerName:""
        },

        methods:{
            search:function () {
                paging.get({
                    title:$('#searchVal').val()
                });
            },
            reload:function () {
                vm.show=true;
                paging.get();
            }
        }
    });
});